package com.xiaoshuidi.cloud.module.member.controller.app.topics;


import com.xiaoshuidi.cloud.framework.common.pojo.CommonResult;
import com.xiaoshuidi.cloud.framework.common.pojo.PageResult;
import com.xiaoshuidi.cloud.module.member.controller.admin.topics.vo.TopicsPostDetailVO;
import com.xiaoshuidi.cloud.module.member.controller.app.topics.vo.AddLikeVo;
import com.xiaoshuidi.cloud.module.member.controller.app.topics.vo.AppTopicsPostPageVO;
import com.xiaoshuidi.cloud.module.member.controller.app.topics.vo.MemberTopicsPostCreateVO;
import com.xiaoshuidi.cloud.module.member.enums.ApiConstants;
import com.xiaoshuidi.cloud.module.member.service.topics.MemberTopicsPostService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.annotation.Resource;
import javax.annotation.security.PermitAll;
import javax.validation.Valid;

import static com.xiaoshuidi.cloud.framework.common.pojo.CommonResult.success;

@Tag(name = "租客APP - 跟帖")
@RestController
@RequestMapping(ApiConstants.NAME + "/topics-post")
@Validated
public class AppMemberTopicsPostController {
    @Resource
    private MemberTopicsPostService memberTopicsPostService;

    @PostMapping("/create")
    @Operation(summary = "跟帖")
    public CommonResult<Boolean> create(@Valid @RequestBody MemberTopicsPostCreateVO createReqVO) {
        return success(memberTopicsPostService.create(createReqVO));
    }

    @PostMapping("/get-page")
    @Operation(summary = "手机获得跟帖列表1最新2推荐")
    @PermitAll
    public CommonResult<PageResult<TopicsPostDetailVO>> getAppPage(@Valid @RequestBody AppTopicsPostPageVO pageVO) {
        PageResult<TopicsPostDetailVO> pageResult = memberTopicsPostService.getAppPage(pageVO);
        return success(pageResult);
    }

    @PostMapping("/add-like")
    @Operation(summary = "点赞")
    public CommonResult<Boolean> addLike(@Valid @RequestBody AddLikeVo addLikeVo) {
        return success(memberTopicsPostService.addLike(addLikeVo));
    }

}
